package com.wnxy.carl.response;

import java.util.List;

public class Result<T> {

    public static final String ADD_FIAIL = "数据添加失败";
    public static final String DELETE_FIAIL = "数据删除失败";
    public static final String UPDATE_FIAIL = "数据修改失败";
    public static final String SELECT_NULL = "未查询到数据";
    public static final String  POWER_LASK = "权限不足";

    private Boolean state;
    private String code;
    private String massage;
    private T data;

    public static  Result<?> build(){
        return new Result<>();
    }
    public Boolean getState() {
        return state;
    }

    public void setState(Boolean state) {
        this.state = state;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMassage() {
        return massage;
    }

    public void setMassage(String massage) {
        this.massage = massage;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public Result() {
    }

    public Result(Boolean state, String coed, String massage, T data) {
        this.state = state;
        this.code = coed;
        this.massage = massage;
        this.data = data;
    }

    public static Result runFail(String massage){
        return new Result(false,"4004",massage,null);
    }
    public static Result runFail(String coed,String massage){
        return new Result(false,coed,massage,null);
    }
    public static Result runFail(Boolean bool,String coed,String massage){
        return new Result(bool,coed,massage,null);
    }


    public static Result checkFail(String massage){
        return new Result(false,"3003",massage,null);
    }

    public static Result fail(String coed,String massage){
        return new Result(false,coed,massage,null);
    }

    public static <T> Result<T> runFail(Class<T> t,String massage ,T data){
        return new Result<T>(false,"4004",massage,data);
    }
    public static <T> Result<T> checkFail(Class<T> t,String massage ,T data){
        return new Result<T>(false,"3003",massage,data);
    }
    public static <T> Result<T> fail(Class<T> t,String coed,String massage ,T data){
        return new Result<T>(false,coed,massage,data);
    }
    public static Result success(String massage){
        return new Result(true,"2002",massage,null);
    }
    public static <T> Result<T> success(Class<T> t,String massage ,T data){
        return new Result<T>(true,"2002",massage,data);
    }
    /**
     *  返回集合泛型
     * @param t List<T> T对象的class
     * @param data list 对象
     * @param <T>
     * @return
     */
    public static <T> Result<List<T>> success(Class<T> t, List<T> data){
        Result<List<T>> listResult = new Result<List<T>>(true,"2002","查询集合成功",data);
        return listResult;
    }

    /**
     * 继承EPage<T> 的对象（接收者不用强转类别对象）
     * @param data
     * @param <T>
     * @return
     */
    public static <T> Result<? extends EPage<T>> success(EPage<T> data){
        return new Result<EPage<T>>(true,"2002","分页查询成功",data);
    }
}
